<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Conditional Execution (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Conditional Execution (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Conditional Execution (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Machine-Desc.html" rel="up" title="Machine Desc">
<link href="Define-Subst.html" rel="next" title="Define Subst">
<link href="Insn-Attributes.html" rel="prev" title="Insn Attributes">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Conditional-Execution">
<div class="nav-panel">
<p>
Next: <a href="Define-Subst.html" accesskey="n" rel="next">RTL Templates Transformations</a>, Previous: <a href="Insn-Attributes.html" accesskey="p" rel="prev">Instruction Attributes</a>, Up: <a href="Machine-Desc.html" accesskey="u" rel="up">Machine Descriptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Conditional-Execution-1"><span>17.20 Conditional Execution<a class="copiable-link" href="#Conditional-Execution-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-conditional-execution"></a>
<a class="index-entry-id" id="index-predication"></a>

<p>A number of architectures provide for some form of conditional
execution, or predication.  The hallmark of this feature is the
ability to nullify most of the instructions in the instruction set.
When the instruction set is large and not entirely symmetric, it
can be quite tedious to describe these forms directly in the
<samp class="file">.md</samp> file.  An alternative is the <code class="code">define_cond_exec</code> template.
</p>
<a class="index-entry-id" id="index-define_005fcond_005fexec"></a>
<div class="example smallexample">
<pre class="example-preformatted">(define_cond_exec
  [<var class="var">predicate-pattern</var>]
  &quot;<var class="var">condition</var>&quot;
  &quot;<var class="var">output-template</var>&quot;
  &quot;<var class="var">optional-insn-attribues</var>&quot;)
</pre></div>

<p><var class="var">predicate-pattern</var> is the condition that must be true for the
insn to be executed at runtime and should match a relational operator.
One can use <code class="code">match_operator</code> to match several relational operators
at once.  Any <code class="code">match_operand</code> operands must have no more than one
alternative.
</p>
<p><var class="var">condition</var> is a C expression that must be true for the generated
pattern to match.
</p>
<a class="index-entry-id" id="index-current_005finsn_005fpredicate"></a>
<p><var class="var">output-template</var> is a string similar to the <code class="code">define_insn</code>
output template (see <a class="pxref" href="Output-Template.html">Output Templates and Operand Substitution</a>), except that the &lsquo;<samp class="samp">*</samp>&rsquo;
and &lsquo;<samp class="samp">@</samp>&rsquo; special cases do not apply.  This is only useful if the
assembly text for the predicate is a simple prefix to the main insn.
In order to handle the general case, there is a global variable
<code class="code">current_insn_predicate</code> that will contain the entire predicate
if the current insn is predicated, and will otherwise be <code class="code">NULL</code>.
</p>
<p><var class="var">optional-insn-attributes</var> is an optional vector of attributes that gets
appended to the insn attributes of the produced cond_exec rtx. It can
be used to add some distinguishing attribute to cond_exec rtxs produced
that way. An example usage would be to use this attribute in conjunction
with attributes on the main pattern to disable particular alternatives under
certain conditions.
</p>
<p>When <code class="code">define_cond_exec</code> is used, an implicit reference to
the <code class="code">predicable</code> instruction attribute is made.
See <a class="xref" href="Insn-Attributes.html">Instruction Attributes</a>.  This attribute must be a boolean (i.e. have
exactly two elements in its <var class="var">list-of-values</var>), with the possible
values being <code class="code">no</code> and <code class="code">yes</code>.  The default and all uses in
the insns must be a simple constant, not a complex expressions.  It
may, however, depend on the alternative, by using a comma-separated
list of values.  If that is the case, the port should also define an
<code class="code">enabled</code> attribute (see <a class="pxref" href="Disable-Insn-Alternatives.html">Disable insn alternatives using the <code class="code">enabled</code> attribute</a>), which
should also allow only <code class="code">no</code> and <code class="code">yes</code> as its values.
</p>
<p>For each <code class="code">define_insn</code> for which the <code class="code">predicable</code>
attribute is true, a new <code class="code">define_insn</code> pattern will be
generated that matches a predicated version of the instruction.
For example,
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_insn &quot;addsi&quot;
  [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;r&quot;)
        (plus:SI (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
                 (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  &quot;<var class="var">test1</var>&quot;
  &quot;add %2,%1,%0&quot;)

(define_cond_exec
  [(ne (match_operand:CC 0 &quot;register_operand&quot; &quot;c&quot;)
       (const_int 0))]
  &quot;<var class="var">test2</var>&quot;
  &quot;(%0)&quot;)
</pre></div>

<p>generates a new pattern
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_insn &quot;&quot;
  [(cond_exec
     (ne (match_operand:CC 3 &quot;register_operand&quot; &quot;c&quot;) (const_int 0))
     (set (match_operand:SI 0 &quot;register_operand&quot; &quot;r&quot;)
          (plus:SI (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
                   (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;))))]
  &quot;(<var class="var">test2</var>) &amp;&amp; (<var class="var">test1</var>)&quot;
  &quot;(%3) add %2,%1,%0&quot;)
</pre></div>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Define-Subst.html">RTL Templates Transformations</a>, Previous: <a href="Insn-Attributes.html">Instruction Attributes</a>, Up: <a href="Machine-Desc.html">Machine Descriptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
